
import hunt.framework;
import hunt.logging.ConsoleLogger;

import app.config.CustomConfig;
import app.grpc.impl;
import repository.UserRepository;
import comm.QueueJob;
import core.thread;
import std.parallelism;

void main(string[] args) {
  // Console app = new Console("IM LogicServer", "1.0.0");
  // app.setAutoExit(false);
  // app.add(new StartAppCommand());
  // app.run(args);

  Application appInstance = Application.instance();

  // appInstance.register(new StartAppCommand());

  appInstance.booting(() {
    appInstance.grpc.server.register( new AuthServiceImpl());
  });

  appInstance.booted(() {
    serverConfig = configManager().load!CustomConfig();

    UserRepository rep = new UserRepository;
    rep.resetStatus();


    auto runTask = task(() {// 离线消息 消息推送给移动端
      QueueJob.getInstance.startJob();
    });
    taskPool.put(runTask);

    startTransportServer();
  } );


  appInstance.run(args);
}


void startTransportServer() {

  import message.Constants;
  import msgtrans;

  MessageTransportServer server = new MessageTransportServer(LogicServerName);

  server.addChannel(new TcpServerChannel(serverConfig.tcpport));

  server.acceptor((TransportContext ctx) {
    infof("New connection: id=%d", ctx.id());
  });

  server.start();
}
